﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace BLL
{
    public class CongDoanBLL
    {
        ChamCongEntities cc = new ChamCongEntities();
        public List<CongDoan> GetAllCongDoan()
        {
            return cc.CongDoans.Include("SanPham").ToList<CongDoan>();
        }

        public List<CongDoan> GetAllCongDoanByMaSP(int spid)
        {
            return cc.CongDoans.Where(cd => cd.SanPhamId == spid).ToList<CongDoan>();
        }
        public CongDoan GetCongDoanById(int id)
        {
            return cc.CongDoans.Where(cd => cd.CongDoanId == id).FirstOrDefault();
        }

        public void InsertCongDoan(CongDoan congDoan)
        {
            cc.Entry(congDoan).State = EntityState.Added;
            cc.SaveChanges();
        }
        public void UpdateCongDoan(CongDoan congDoan)
        {
            cc.Entry(congDoan).State = EntityState.Modified;
            cc.SaveChanges();
        }
        public bool DeleteCongDoan(CongDoan congDoan)
        {
            cc.Entry(congDoan).State = EntityState.Deleted;
            return cc.SaveChanges() > 0;
        }
    }
}
